package ubcns.lib.image;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.widget.ImageView;


public class ImageDownLoad {
	
    String imgUrl = "http://192.168.0.171/upload/";

    Back task;
    Bitmap bm;
    ImageView ivIndvdl;
    int cnt = 0;
    
	public ImageDownLoad(ImageView _ivIndvdl) {
		this.ivIndvdl = _ivIndvdl;

	}
	
	
    private class Back extends AsyncTask<String, Integer,Bitmap>{
            	 
        @Override
        protected Bitmap doInBackground(String... urls) {
        
        	try{
            
        		URL myFileUrl = new URL(urls[0]);
                HttpURLConnection conn = (HttpURLConnection)myFileUrl.openConnection();
                conn.setDoInput(true);
                conn.connect();
                
                InputStream is = conn.getInputStream();
                
                bm = BitmapFactory.decodeStream(is);
                
                
            }catch(IOException e){
                e.printStackTrace();
            }
            return bm;
        }
        
        protected void onPostExecute(Bitmap img){
            ivIndvdl.setImageBitmap(bm);
        }
        
        
        
    }
    
    public void getImage(String imageName){
    	
		task = new Back();
        task.execute(imgUrl+imageName+".jpg");
    }
}
